import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/user_model.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';

class IntroView extends StatefulWidget {
  final UserModel model;
  const IntroView({Key? key,required this.model}) : super(key: key);

  @override
  _IntroViewState createState() => _IntroViewState();
}

class _IntroViewState extends State<IntroView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 20, right: 20, top: 15, bottom: 0),
      margin: EdgeInsets.only(top: kToolbarHeight + 40),
      color: Colors.white,
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _iconWidget(),
            SizedBox(height: 20,),
            Text(
              '厨娘  豆龄 5.7岁  内蒙古 呼和汉特',
              style: TextStyle(
                  fontWeight: FontWeight.w500,
                  fontSize: 15,
                  color: Colors.black),
            ),
            SizedBox(height: 5,),
            Text(
              widget.model.n!,
              style: TextStyle(
                  fontSize: 13,
                  color: AppColors.black),
            ),
            SizedBox(height: 25,),
            _countWiget(),
          ],
        ),
      ),
    );
  }

  /// 用户头像 简介
  Widget _iconWidget() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        IconImage(
            url:
                widget.model.p!,
            width: 80,
            height: 80,
            radius: 40,
            borderWidth: 1,
            borderColor: Colors.transparent),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Text(
                  widget.model.n!,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    fontSize: 18,
                    fontWeight: FontWeight.w500,
                    color: Colors.black,
                  ),
                ),
                SizedBox(
                  width: 8,
                ),
                Text(
                  'LV.${widget.model.lvl!}',
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                      fontSize: 11,
                      color: AppColors.yellow,
                      fontStyle: FontStyle.italic,
                      fontWeight: FontWeight.bold),
                ),
              ],
            ),
            SizedBox(
              height: 5,
            ),
            SizedBox(
              width: MediaQuery.of(context).size.width - 140,
              height: 32,
              child: FlatButton(
                onPressed: () => print(''),
                child: Text(
                  '关注',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 12,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                color: Colors.amber,
                shape: RoundedRectangleBorder(
                    side: BorderSide(
                      color: Colors.amber,
                      width: 0.5,
                    ),
                    borderRadius: BorderRadius.circular(16)),
              ),
            ),
          ],
        ),
      ],
    );
  }

  /// 数据widget
  Widget _countWiget(){
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        _countItemWiget('9', '关注'),
        _countItemWiget('6060', '粉丝'),
        _countItemWiget('1.2万', '被收藏'),
        _countItemWiget('29', '被学做'),
        _countItemWiget('3488', '经验值'),
      ],
    );
  }

  Widget _countItemWiget(String titel,String countstr){
    return Column(
      children: [
        Text(
          titel,
          style: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 15,
              color: Colors.black),
        ),
        SizedBox(height: 5,),
        Text(
          countstr,
          style: TextStyle(
              fontSize: 13,
              color: AppColors.black),
        ),
      ],
    );
  }

}
